home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / 3grenade.zip / WEAPONS.QC < prev   
Text File  |  1996-08-23  |  38KB  |  1,663 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9.  
  10. // called by worldspawn
  11. void() W_Precache =
  12. {
  13.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  14.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  15.     precache_sound ("weapons/sgun1.wav");
  16.     precache_sound ("weapons/guncock.wav");    // player shotgun
  17.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  20.     precache_sound ("weapons/spike2.wav");    // super spikes
  21.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  22.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  23.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  24.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  25.         precache_sound ("items/protect2.wav");  //pent
  26.         precache_sound ("items/suit2.wav");     //biosuit
  27.         precache_sound ("items/inv3.wav");      //invis
  28.         precache_sound ("items/inv2.wav");      //invis2
  29.         precache_sound ("items/damage2.wav");   //quad
  30.         precache_sound ("items/protect3.wav");  //pent2
  31.         precache_model ("progs/h_shams.mdl");   //shambler head
  32.         precache_model ("progs/gib1.mdl");      //body part
  33.         precache_model ("progs/h_ogre.mdl");    //ogre head
  34.         precache_model ("progs/gib2.mdl");      //body part 2
  35.         precache_model ("progs/gib3.mdl");      //body part 3
  36.         precache_model ("progs/h_player.mdl");  //player head
  37.         precache_model ("progs/h_demon.mdl");   //demon head
  38.         precache_model ("progs/h_guard.mdl");   //grunt head
  39.         precache_model ("progs/h_knight.mdl");  //knight head
  40. };
  41.  
  42. float() crandom =
  43. {
  44.     return 2*(random() - 0.5);
  45. };
  46.  
  47. /*
  48. ================
  49. W_FireAxe
  50. ================
  51. */
  52. void() W_FireAxe =
  53. {
  54.     local    vector    source;
  55.     local    vector    org;
  56.  
  57.     source = self.origin + '0 0 16';
  58.     traceline (source, source + v_forward*64, FALSE, self);
  59.     if (trace_fraction == 1.0)
  60.         return;
  61.     
  62.     org = trace_endpos - v_forward*4;
  63.  
  64.     if (trace_ent.takedamage)
  65.     {
  66.         trace_ent.axhitme = 1;
  67.         SpawnBlood (org, '0 0 0', 20);
  68.         T_Damage (trace_ent, self, self, 20);
  69.     }
  70.     else
  71.     {    // hit wall
  72.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  73.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  74.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  75.         WriteCoord (MSG_BROADCAST, org_x);
  76.         WriteCoord (MSG_BROADCAST, org_y);
  77.         WriteCoord (MSG_BROADCAST, org_z);
  78.     }
  79. };
  80.  
  81.  
  82. //============================================================================
  83.  
  84.  
  85. vector() wall_velocity =
  86. {
  87.     local vector    vel;
  88.     
  89.     vel = normalize (self.velocity);
  90.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  91.     vel = vel + 2*trace_plane_normal;
  92.     vel = vel * 200;
  93.     
  94.     return vel;
  95. };
  96.  
  97.  
  98. /*
  99. ================
  100. SpawnMeatSpray
  101. ================
  102. */
  103. void(vector org, vector vel) SpawnMeatSpray =
  104. {
  105.     local    entity missile, mpuff;
  106.     local    vector    org;
  107.  
  108.     missile = spawn ();
  109.     missile.owner = self;
  110.     missile.movetype = MOVETYPE_BOUNCE;
  111.     missile.solid = SOLID_NOT;
  112.  
  113.     makevectors (self.angles);
  114.  
  115.     missile.velocity = vel;
  116.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  117.  
  118.     missile.avelocity = '3000 1000 2000';
  119.     
  120. // set missile duration
  121.     missile.nextthink = time + 1;
  122.     missile.think = SUB_Remove;
  123.  
  124.     setmodel (missile, "progs/zom_gib.mdl");
  125.     setsize (missile, '0 0 0', '0 0 0');        
  126.     setorigin (missile, org);
  127. };
  128.  
  129. /*
  130. ================
  131. SpawnBlood
  132. ================
  133. */
  134. void(vector org, vector vel, float damage) SpawnBlood =
  135. {
  136.     particle (org, vel*0.1, 73, damage*2);
  137. };
  138.  
  139. /*
  140. ================
  141. spawn_touchblood
  142. ================
  143. */
  144. void(float damage) spawn_touchblood =
  145. {
  146.     local vector    vel;
  147.  
  148.     vel = wall_velocity () * 0.2;
  149.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  150. };
  151.  
  152.  
  153. /*
  154. ================
  155. SpawnChunk
  156. ================
  157. */
  158. void(vector org, vector vel) SpawnChunk =
  159. {
  160.     particle (org, vel*0.02, 0, 10);
  161. };
  162.  
  163. /*
  164. ==============================================================================
  165.  
  166. MULTI-DAMAGE
  167.  
  168. Collects multiple small damages into a single damage
  169.  
  170. ==============================================================================
  171. */
  172.  
  173. entity    multi_ent;
  174. float    multi_damage;
  175.  
  176. void() ClearMultiDamage =
  177. {
  178.     multi_ent = world;
  179.     multi_damage = 0;
  180. };
  181.  
  182. void() ApplyMultiDamage =
  183. {
  184.     if (!multi_ent)
  185.         return;
  186.     T_Damage (multi_ent, self, self, multi_damage);
  187. };
  188.  
  189. void(entity hit, float damage) AddMultiDamage =
  190. {
  191.     if (!hit)
  192.         return;
  193.     
  194.     if (hit != multi_ent)
  195.     {
  196.         ApplyMultiDamage ();
  197.         multi_damage = damage;
  198.         multi_ent = hit;
  199.     }
  200.     else
  201.         multi_damage = multi_damage + damage;
  202. };
  203.  
  204. /*
  205. ==============================================================================
  206.  
  207. BULLETS
  208.  
  209. ==============================================================================
  210. */
  211.  
  212. /*
  213. ================
  214. TraceAttack
  215. ================
  216. */
  217. void(float damage, vector dir) TraceAttack =
  218. {
  219.     local    vector    vel, org;
  220.     
  221.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  222.     vel = vel + 2*trace_plane_normal;
  223.     vel = vel * 200;
  224.  
  225.     org = trace_endpos - dir*4;
  226.  
  227.     if (trace_ent.takedamage)
  228.     {
  229.         SpawnBlood (org, vel*0.2, damage);
  230.         AddMultiDamage (trace_ent, damage);
  231.     }
  232.     else
  233.     {
  234.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  235.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  236.         WriteCoord (MSG_BROADCAST, org_x);
  237.         WriteCoord (MSG_BROADCAST, org_y);
  238.         WriteCoord (MSG_BROADCAST, org_z);
  239.     }
  240. };
  241.  
  242. /*
  243. ================
  244. FireBullets
  245.  
  246. Used by shotgun, super shotgun, and enemy soldier firing
  247. Go to the trouble of combining multiple pellets into a single damage call.
  248. ================
  249. */
  250. void(float shotcount, vector dir, vector spread) FireBullets =
  251. {
  252.     local    vector direction;
  253.     local    vector    src;
  254.     
  255.     makevectors(self.v_angle);
  256.  
  257.     src = self.origin + v_forward*10;
  258.     src_z = self.absmin_z + self.size_z * 0.7;
  259.  
  260.     ClearMultiDamage ();
  261.     while (shotcount > 0)
  262.     {
  263.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  264.  
  265.         traceline (src, src + direction*2048, FALSE, self);
  266.         if (trace_fraction != 1.0)
  267.             TraceAttack (4, direction);
  268.  
  269.         shotcount = shotcount - 1;
  270.     }
  271.     ApplyMultiDamage ();
  272. };
  273.  
  274. /*
  275. ================
  276. W_FireShotgun
  277. ================
  278. */
  279. void() W_FireShotgun =
  280. {
  281.     local vector dir;
  282.  
  283.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  284.  
  285.     self.punchangle_x = -2;
  286.     
  287.         self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  288.     dir = aim (self, 100000);
  289.     FireBullets (6, dir, '0.04 0.04 0');
  290. };
  291.  
  292.  
  293. /*
  294. ================
  295. W_FireSuperShotgun
  296. ================
  297. */
  298. void() W_FireSuperShotgun =
  299. {
  300.     local vector dir;
  301.  
  302.     if (self.currentammo == 1)
  303.     {
  304.         W_FireShotgun ();
  305.         return;
  306.     }
  307.         
  308.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  309.  
  310.     self.punchangle_x = -4;
  311.     
  312.         self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  313.     dir = aim (self, 100000);
  314.     FireBullets (14, dir, '0.14 0.08 0');
  315. };
  316.  
  317.  
  318. /*
  319. ==============================================================================
  320.  
  321. ROCKETS
  322.  
  323. ==============================================================================
  324. */
  325.  
  326. void()    s_explode1    =    [0,        s_explode2] {};
  327. void()    s_explode2    =    [1,        s_explode3] {};
  328. void()    s_explode3    =    [2,        s_explode4] {};
  329. void()    s_explode4    =    [3,        s_explode5] {};
  330. void()    s_explode5    =    [4,        s_explode6] {};
  331. void()    s_explode6    =    [5,        SUB_Remove] {};
  332.  
  333. void() BecomeExplosion =
  334. {
  335.     self.movetype = MOVETYPE_NONE;
  336.     self.velocity = '0 0 0';
  337.     self.touch = SUB_Null;
  338.     setmodel (self, "progs/s_explod.spr");
  339.     self.solid = SOLID_NOT;
  340.     s_explode1 ();
  341. };
  342.  
  343. void() T_MissileTouch =
  344. {
  345.     local float    damg;
  346.  
  347.     if (other == self.owner)
  348.         return;        // don't explode on owner
  349.  
  350.     if (pointcontents(self.origin) == CONTENT_SKY)
  351.     {
  352.         remove(self);
  353.         return;
  354.     }
  355.  
  356.     damg = 100 + random()*20;
  357.     
  358.     if (other.health)
  359.     {
  360.         if (other.classname == "monster_shambler")
  361.             damg = damg * 0.5;    // mostly immune
  362.         T_Damage (other, self, self.owner, damg );
  363.     }
  364.  
  365.     // don't do radius damage to the other, because all the damage
  366.     // was done in the impact
  367.     T_RadiusDamage (self, self.owner, 120, other);
  368.  
  369. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  370.     self.origin = self.origin - 8*normalize(self.velocity);
  371.  
  372.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  373.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  374.     WriteCoord (MSG_BROADCAST, self.origin_x);
  375.     WriteCoord (MSG_BROADCAST, self.origin_y);
  376.     WriteCoord (MSG_BROADCAST, self.origin_z);
  377.  
  378.     BecomeExplosion ();
  379. };
  380.  
  381.  
  382.  
  383. /*
  384. ================
  385. W_FireRocket
  386. ================
  387. */
  388. void() W_FireRocket =
  389. {
  390.     local    entity missile, mpuff;
  391.     
  392.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  393.     
  394.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  395.  
  396.     self.punchangle_x = -2;
  397.  
  398.     missile = spawn ();
  399.     missile.owner = self;
  400.     missile.movetype = MOVETYPE_FLYMISSILE;
  401.     missile.solid = SOLID_BBOX;
  402.         
  403. // set missile speed    
  404.  
  405.     makevectors (self.v_angle);
  406.     missile.velocity = aim(self, 1000);
  407.     missile.velocity = missile.velocity * 1000;
  408.     missile.angles = vectoangles(missile.velocity);
  409.     
  410.     missile.touch = T_MissileTouch;
  411.     
  412. // set missile duration
  413.     missile.nextthink = time + 5;
  414.     missile.think = SUB_Remove;
  415.  
  416.     setmodel (missile, "progs/missile.mdl");
  417.     setsize (missile, '0 0 0', '0 0 0');        
  418.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  419. };
  420.  
  421. /*
  422. ===============================================================================
  423.  
  424. LIGHTNING
  425.  
  426. ===============================================================================
  427. */
  428.  
  429. /*
  430. =================
  431. LightningDamage
  432. =================
  433. */
  434. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  435. {
  436.     local entity        e1, e2;
  437.     local vector        f;
  438.     
  439.     f = p2 - p1;
  440.     normalize (f);
  441.     f_x = 0 - f_y;
  442.     f_y = f_x;
  443.     f_z = 0;
  444.     f = f*16;
  445.  
  446.     e1 = e2 = world;
  447.  
  448.     traceline (p1, p2, FALSE, self);
  449.     if (trace_ent.takedamage)
  450.     {
  451.         particle (trace_endpos, '0 0 100', 225, damage*4);
  452.         T_Damage (trace_ent, from, from, damage);
  453.         if (self.classname == "player")
  454.         {
  455.             if (other.classname == "player")
  456.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  457.         }
  458.     }
  459.     e1 = trace_ent;
  460.  
  461.     traceline (p1 + f, p2 + f, FALSE, self);
  462.     if (trace_ent != e1 && trace_ent.takedamage)
  463.     {
  464.         particle (trace_endpos, '0 0 100', 225, damage*4);
  465.         T_Damage (trace_ent, from, from, damage);
  466.     }
  467.     e2 = trace_ent;
  468.  
  469.     traceline (p1 - f, p2 - f, FALSE, self);
  470.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  471.     {
  472.         particle (trace_endpos, '0 0 100', 225, damage*4);
  473.         T_Damage (trace_ent, from, from, damage);
  474.     }
  475. };
  476.  
  477.  
  478. void() W_FireLightning =
  479. {
  480.     local    vector        org;
  481.  
  482.     if (self.ammo_cells < 1)
  483.     {
  484.         self.weapon = W_BestWeapon ();
  485.         W_SetCurrentAmmo ();
  486.         return;
  487.     }
  488.  
  489. // explode if under water
  490.     if (self.waterlevel > 1)
  491.     {
  492.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  493.                 self.ammo_cells = 0;
  494.         W_SetCurrentAmmo ();
  495.         return;
  496.     }
  497.  
  498.     if (self.t_width < time)
  499.     {
  500.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  501.         self.t_width = time + 0.6;
  502.     }
  503.     self.punchangle_x = -2;
  504.  
  505.         self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  506.  
  507.     org = self.origin + '0 0 16';
  508.     
  509.     traceline (org, org + v_forward*600, TRUE, self);
  510.  
  511.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  512.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  513.     WriteEntity (MSG_BROADCAST, self);
  514.     WriteCoord (MSG_BROADCAST, org_x);
  515.     WriteCoord (MSG_BROADCAST, org_y);
  516.     WriteCoord (MSG_BROADCAST, org_z);
  517.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  518.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  519.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  520.  
  521.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  522. };
  523.  
  524.  
  525. //=============================================================================
  526. void() DetPipeBombs =
  527. {
  528.         local entity    head;
  529.  
  530.         head = findradius (self.origin, 10000);
  531.         while(head)
  532.         {
  533.                 if((head.classname == "pipebomb") && (head.owner == self))
  534.                         head.nextthink = time;
  535.                 head = head.chain;
  536.         }
  537. };
  538. float temp2=1;
  539. void() GrenadeExplode =
  540. {
  541. T_RadiusDamage (self, self.owner, 120, world);
  542. WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  543. WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  544. WriteCoord (MSG_BROADCAST, self.origin_x);
  545. WriteCoord (MSG_BROADCAST, self.origin_y);
  546. WriteCoord (MSG_BROADCAST, self.origin_z);
  547.  
  548. BecomeExplosion ();
  549.  
  550. };
  551. void() PipeBombTouch =
  552. {
  553.     if (other == self.owner)
  554.         return;        // don't explode on owner
  555.         sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);  // bounce sound
  556.     if (self.velocity == '0 0 0')
  557.         self.avelocity = '0 0 0';
  558. };   
  559.         
  560.  
  561. void() W_FirePipeBomb =
  562. {       
  563.     local    entity missile, mpuff;
  564.     
  565.     if(self.ammo_rockets < 1)    // have to have ammo
  566.       return;
  567.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  568.     
  569.         sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  570.  
  571. //    self.punchangle_x = -2;
  572.  
  573.     missile = spawn ();
  574.     missile.owner = self;
  575.     missile.movetype = MOVETYPE_BOUNCE;
  576.     missile.solid = SOLID_BBOX;
  577.     missile.classname = "pipebomb";
  578.         
  579. // set missile speed    
  580.  
  581.     makevectors (self.v_angle);
  582.  
  583.     if (self.v_angle_x)
  584.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  585.     else
  586.     {
  587.         missile.velocity = aim(self, 10000);
  588.         missile.velocity = missile.velocity * 600;
  589.         missile.velocity_z = 200;
  590.     }
  591.  
  592.     missile.avelocity = '300 300 300';
  593.  
  594.     missile.angles = vectoangles(missile.velocity);
  595.     
  596.     missile.touch = PipeBombTouch;
  597.     missile.think = GrenadeExplode;
  598.         if (temp2 == 1)
  599.         setmodel (missile, "progs/grenade.mdl");
  600.         if (temp2 == 2)
  601.         setmodel (missile, "progs/h_ogre.mdl");
  602.         if (temp2 == 3)
  603.         setmodel (missile, "progs/gib1.mdl");
  604.         if (temp2 == 4)
  605.         setmodel (missile, "progs/gib2.mdl");
  606.         if (temp2 == 5)
  607.         setmodel (missile, "progs/gib3.mdl");
  608.         if (temp2 == 6)
  609.         setmodel (missile, "progs/h_player.mdl");
  610.         if (temp2 == 7)
  611.         setmodel (missile, "progs/h_demon.mdl");
  612.         if (temp2 == 8)
  613.         setmodel (missile, "progs/h_shams.mdl");
  614.         if (temp2 == 9)
  615.         setmodel (missile, "progs/h_knight.mdl");
  616.         if (temp2 == 10)
  617.         setmodel (missile, "progs/h_guard.mdl");
  618.         setsize (missile, '0 0 0', '0 0 0');     
  619.     setorigin (missile, self.origin);
  620. };
  621. void() GrenadeTouch =
  622. {
  623.     if (other == self.owner)
  624.         return;        // don't explode on owner
  625.     if (other.takedamage == DAMAGE_AIM)
  626.     {
  627.         GrenadeExplode();
  628.         return;
  629.     }
  630.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  631.     if (self.velocity == '0 0 0')
  632.         self.avelocity = '0 0 0';
  633. };
  634.  
  635. /*
  636. ================
  637. W_FireGrenade
  638. ================
  639. */
  640. void() CheckProximity;
  641. void() ActivateMine =
  642. {
  643.         sprint(self.owner,"Mine Armed.\n");
  644.         self.nextthink=time+0.1;
  645.         self.think=CheckProximity;
  646. };
  647.  
  648. void() T_ProximityTouch =
  649. {
  650.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  651.         sprint(self.owner,"You have 3 seconds to get away.\n");
  652.         self.nextthink=time+3;
  653.         self.think=ActivateMine;
  654.         return;
  655. };
  656.  
  657. void() T_ProximityBlowUp;
  658.  
  659. void() CheckProximity =
  660. {
  661.     local entity head, selected;
  662.     local float dist;
  663.     dist = 128;
  664.     selected = world;
  665.     head = findradius(self.origin, 128);
  666.     while(head)
  667.     {
  668.                 if( (head.health > 1) && (head != self) )
  669.         {
  670.             traceline(self.origin,head.origin,TRUE,self);
  671.             if ( (vlen(head.origin - self.origin) < dist) )
  672.             {
  673.                 selected = head;
  674.                 dist = vlen(head.origin - self.origin);
  675.             }
  676.         }
  677.         head = head.chain;
  678.     }
  679.     if (dist<128)
  680.         {
  681.         T_ProximityBlowUp();
  682.         return;
  683.         }
  684.     self.nextthink = 0.5;
  685.     self.think = CheckProximity;
  686. };
  687. void() T_ProximityBlowUp =
  688. {
  689.     local float    damg;
  690.  
  691.     if (pointcontents(self.origin) == CONTENT_SKY)
  692.     {
  693.         remove(self);
  694.         return;
  695.     }
  696.  
  697.         if (other.health)
  698.     {
  699.         if (other.classname == "monster_shambler")
  700.             damg = damg * 0.5;    // mostly immune
  701.         T_Damage (other, self, self.owner, damg );
  702.     }
  703.  
  704.     // don't do radius damage to the other, because all the damage
  705.     // was done in the impact
  706.         T_RadiusDamage (self, self.owner, 120, other);
  707.  
  708. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  709.     self.origin = self.origin - 8*normalize(self.velocity);
  710.  
  711.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  712.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  713.     WriteCoord (MSG_BROADCAST, self.origin_x);
  714.     WriteCoord (MSG_BROADCAST, self.origin_y);
  715.     WriteCoord (MSG_BROADCAST, self.origin_z);
  716.  
  717.     BecomeExplosion ();
  718. };
  719.  
  720. void() W_FireGrenade =
  721. {
  722.     local    entity missile, mpuff;
  723.     
  724.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  725.     
  726.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  727.  
  728.     self.punchangle_x = -2;
  729.  
  730.     missile = spawn ();
  731.     missile.owner = self;
  732.     missile.movetype = MOVETYPE_BOUNCE;
  733.     missile.solid = SOLID_BBOX;
  734.     missile.classname = "grenade";
  735.         
  736. // set missile speed    
  737.  
  738.     makevectors (self.v_angle);
  739.  
  740.     if (self.v_angle_x)
  741.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  742.     else
  743.     {
  744.         missile.velocity = aim(self, 10000);
  745.         missile.velocity = missile.velocity * 600;
  746.         missile.velocity_z = 200;
  747.     }
  748.  
  749.     missile.avelocity = '300 300 300';
  750.  
  751.     missile.angles = vectoangles(missile.velocity);
  752.     
  753.     missile.touch = GrenadeTouch;
  754.         missile.nextthink = time + (cvar("temp1")+0);
  755.         missile.think = GrenadeExplode;
  756.         
  757.         if (temp2 == 1)
  758.         setmodel (missile, "progs/grenade.mdl");
  759.         if (temp2 == 2)
  760.         setmodel (missile, "progs/h_ogre.mdl");
  761.         if (temp2 == 3)
  762.         setmodel (missile, "progs/gib1.mdl");
  763.         if (temp2 == 4)
  764.         setmodel (missile, "progs/gib2.mdl");
  765.         if (temp2 == 5)
  766.         setmodel (missile, "progs/gib3.mdl");
  767.         if (temp2 == 6)
  768.         setmodel (missile, "progs/h_player.mdl");
  769.         if (temp2 == 7)
  770.         setmodel (missile, "progs/h_demon.mdl");
  771.         if (temp2 == 8)
  772.         setmodel (missile, "progs/h_shams.mdl");
  773.         if (temp2 == 9)
  774.         setmodel (missile, "progs/h_knight.mdl");
  775.         if (temp2 == 10)
  776.         setmodel (missile, "progs/h_guard.mdl");
  777.         setsize (missile, '0 0 0', '0 0 0');     
  778.     setorigin (missile, self.origin);
  779. };
  780. void() W_LayProximityMine =
  781. {
  782.     local    entity missile, mpuff;
  783.     
  784.         self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  785.     
  786.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  787.  
  788.     self.punchangle_x = -2;
  789.  
  790.     missile = spawn ();
  791.     missile.owner = self;
  792.     missile.movetype = MOVETYPE_BOUNCE;
  793.     missile.solid = SOLID_BBOX;
  794.         missile.classname = "mine";
  795.         
  796. // set missile speed    
  797.  
  798.     makevectors (self.v_angle);
  799.  
  800.     if (self.v_angle_x)
  801.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  802.     else
  803.     {
  804.         missile.velocity = aim(self, 10000);
  805.         missile.velocity = missile.velocity * 600;
  806.         missile.velocity_z = 200;
  807.     }
  808.  
  809.     missile.avelocity = '300 300 300';
  810.  
  811.     missile.angles = vectoangles(missile.velocity);
  812.     missile.touch = T_ProximityTouch;
  813.         if (temp2 == 1)
  814.         setmodel (missile, "progs/grenade.mdl");
  815.         if (temp2 == 2)
  816.         setmodel (missile, "progs/h_ogre.mdl");
  817.         if (temp2 == 3)
  818.         setmodel (missile, "progs/gib1.mdl");
  819.         if (temp2 == 4)
  820.         setmodel (missile, "progs/gib2.mdl");
  821.         if (temp2 == 5)
  822.         setmodel (missile, "progs/gib3.mdl");
  823.         if (temp2 == 6)
  824.         setmodel (missile, "progs/h_player.mdl");
  825.         if (temp2 == 7)
  826.         setmodel (missile, "progs/h_demon.mdl");
  827.         if (temp2 == 8)
  828.         setmodel (missile, "progs/h_shams.mdl");
  829.         if (temp2 == 9)
  830.         setmodel (missile, "progs/h_knight.mdl");
  831.         if (temp2 == 10)
  832.         setmodel (missile, "progs/h_guard.mdl");
  833.         setsize (missile, '0 0 0', '0 0 0');     
  834.     setorigin (missile, self.origin);
  835. };
  836.  
  837. //=============================================================================
  838.  
  839. void() spike_touch;
  840. void() superspike_touch;
  841.  
  842.  
  843. /*
  844. ===============
  845. launch_spike
  846.  
  847. Used for both the player and the ogre
  848. ===============
  849. */
  850. void(vector org, vector dir) launch_spike =
  851. {
  852.     newmis = spawn ();
  853.     newmis.owner = self;
  854.     newmis.movetype = MOVETYPE_FLYMISSILE;
  855.     newmis.solid = SOLID_BBOX;
  856.  
  857.     newmis.angles = vectoangles(dir);
  858.     
  859.     newmis.touch = spike_touch;
  860.     newmis.classname = "spike";
  861.     newmis.think = SUB_Remove;
  862.     newmis.nextthink = time + 6;
  863.     setmodel (newmis, "progs/spike.mdl");
  864.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  865.     setorigin (newmis, org);
  866.  
  867.     newmis.velocity = dir * 1000;
  868. };
  869.  
  870. void() W_FireSuperSpikes =
  871. {
  872.     local vector    dir;
  873.     local entity    old;
  874.     
  875.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  876.     self.attack_finished = time + 0.2;
  877.         self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  878.     dir = aim (self, 1000);
  879.     launch_spike (self.origin + '0 0 16', dir);
  880.     newmis.touch = superspike_touch;
  881.     setmodel (newmis, "progs/s_spike.mdl");
  882.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  883.     self.punchangle_x = -2;
  884. };
  885.  
  886. void(float ox) W_FireSpikes =
  887. {
  888.     local vector    dir;
  889.     local entity    old;
  890.     
  891.     makevectors (self.v_angle);
  892.     
  893.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  894.     {
  895.         W_FireSuperSpikes ();
  896.         return;
  897.     }
  898.  
  899.     if (self.ammo_nails < 1)
  900.     {
  901.         self.weapon = W_BestWeapon ();
  902.         W_SetCurrentAmmo ();
  903.         return;
  904.     }
  905.  
  906.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  907.     self.attack_finished = time + 0.2;
  908.         self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  909.         dir = aim (self, 1000);
  910.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  911.  
  912.     self.punchangle_x = -2;
  913. };
  914.  
  915.  
  916.  
  917. .float hit_z;
  918. void() spike_touch =
  919. {
  920. local float rand;
  921.     if (other == self.owner)
  922.         return;
  923.  
  924.     if (other.solid == SOLID_TRIGGER)
  925.         return;    // trigger field, do nothing
  926.  
  927.     if (pointcontents(self.origin) == CONTENT_SKY)
  928.     {
  929.         remove(self);
  930.         return;
  931.     }
  932.     
  933. // hit something that bleeds
  934.     if (other.takedamage)
  935.     {
  936.         spawn_touchblood (9);
  937.         T_Damage (other, self, self.owner, 9);
  938.     }
  939.     else
  940.     {
  941.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  942.         
  943.         if (self.classname == "wizspike")
  944.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  945.         else if (self.classname == "knightspike")
  946.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  947.         else
  948.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  949.         WriteCoord (MSG_BROADCAST, self.origin_x);
  950.         WriteCoord (MSG_BROADCAST, self.origin_y);
  951.         WriteCoord (MSG_BROADCAST, self.origin_z);
  952.     }
  953.  
  954.     remove(self);
  955.  
  956. };
  957.  
  958. void() superspike_touch =
  959. {
  960. local float rand;
  961.     if (other == self.owner)
  962.         return;
  963.  
  964.     if (other.solid == SOLID_TRIGGER)
  965.         return;    // trigger field, do nothing
  966.  
  967.     if (pointcontents(self.origin) == CONTENT_SKY)
  968.     {
  969.         remove(self);
  970.         return;
  971.     }
  972.     
  973. // hit something that bleeds
  974.     if (other.takedamage)
  975.     {
  976.         spawn_touchblood (18);
  977.         T_Damage (other, self, self.owner, 18);
  978.     }
  979.     else
  980.     {
  981.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  982.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  983.         WriteCoord (MSG_BROADCAST, self.origin_x);
  984.         WriteCoord (MSG_BROADCAST, self.origin_y);
  985.         WriteCoord (MSG_BROADCAST, self.origin_z);
  986.     }
  987.  
  988.     remove(self);
  989.  
  990. };
  991.  
  992.  
  993. /*
  994. ===============================================================================
  995.  
  996. PLAYER WEAPON USE
  997.  
  998. ===============================================================================
  999. */
  1000.  
  1001. void() W_SetCurrentAmmo =
  1002. {
  1003.     player_run ();        // get out of any weapon firing states
  1004.  
  1005.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  1006.     
  1007.     if (self.weapon == IT_AXE)
  1008.     {
  1009.         self.currentammo = 0;
  1010.         self.weaponmodel = "progs/v_axe.mdl";
  1011.         self.weaponframe = 0;
  1012.     }
  1013.     else if (self.weapon == IT_SHOTGUN)
  1014.     {
  1015.         self.currentammo = self.ammo_shells;
  1016.         self.weaponmodel = "progs/v_shot.mdl";
  1017.         self.weaponframe = 0;
  1018.         self.items = self.items | IT_SHELLS;
  1019.     }
  1020.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1021.     {
  1022.         self.currentammo = self.ammo_shells;
  1023.         self.weaponmodel = "progs/v_shot2.mdl";
  1024.         self.weaponframe = 0;
  1025.         self.items = self.items | IT_SHELLS;
  1026.     }
  1027.     else if (self.weapon == IT_NAILGUN)
  1028.     {
  1029.         self.currentammo = self.ammo_nails;
  1030.         self.weaponmodel = "progs/v_nail.mdl";
  1031.         self.weaponframe = 0;
  1032.         self.items = self.items | IT_NAILS;
  1033.     }
  1034.     else if (self.weapon == IT_SUPER_NAILGUN)
  1035.     {
  1036.         self.currentammo = self.ammo_nails;
  1037.         self.weaponmodel = "progs/v_nail2.mdl";
  1038.         self.weaponframe = 0;
  1039.         self.items = self.items | IT_NAILS;
  1040.     }
  1041.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1042.     {
  1043.         self.currentammo = self.ammo_rockets;
  1044.         self.weaponmodel = "progs/v_rock.mdl";
  1045.         self.weaponframe = 0;
  1046.         self.items = self.items | IT_ROCKETS;
  1047.     }
  1048.         else if (self.weapon == IT_PIPEBOMB_LAUNCHER)
  1049.     {
  1050.         self.currentammo = self.ammo_rockets;
  1051.         self.weaponmodel = "progs/v_rock.mdl";
  1052.         self.weaponframe = 0;
  1053.         self.items = self.items | IT_ROCKETS;
  1054.     }
  1055.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  1056.     {
  1057.         self.currentammo = self.ammo_rockets;
  1058.         self.weaponmodel = "progs/v_rock2.mdl";
  1059.         self.weaponframe = 0;
  1060.         self.items = self.items | IT_ROCKETS;
  1061.     }
  1062.         else if (self.weapon == IT_MINE_LAUNCHER)
  1063.         {
  1064.                 self.currentammo = self.ammo_rockets;
  1065.                 self.weaponmodel = "progs/v_rock.mdl";
  1066.                 self.weaponframe = 0;
  1067.                 self.items = self.items | IT_ROCKETS;
  1068.         }
  1069.     else if (self.weapon == IT_LIGHTNING)
  1070.     {
  1071.         self.currentammo = self.ammo_cells;
  1072.         self.weaponmodel = "progs/v_light.mdl";
  1073.         self.weaponframe = 0;
  1074.         self.items = self.items | IT_CELLS;
  1075.     }
  1076.     else
  1077.     {
  1078.         self.currentammo = 0;
  1079.         self.weaponmodel = "";
  1080.         self.weaponframe = 0;
  1081.     }
  1082. };
  1083.  
  1084. float() W_BestWeapon =
  1085. {
  1086.     local    float    it;
  1087.     
  1088.     it = self.items;
  1089.  
  1090.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  1091.         return IT_LIGHTNING;
  1092.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  1093.         return IT_SUPER_NAILGUN;
  1094.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  1095.         return IT_SUPER_SHOTGUN;
  1096.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  1097.         return IT_NAILGUN;
  1098.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  1099.         return IT_SHOTGUN;
  1100.         
  1101. /*
  1102.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  1103.         return IT_ROCKET_LAUNCHER;
  1104.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  1105.         return IT_GRENADE_LAUNCHER;
  1106.  
  1107. */
  1108.  
  1109.     return IT_AXE;
  1110. };
  1111.  
  1112. float() W_CheckNoAmmo =
  1113. {
  1114.     if (self.currentammo > 0)
  1115.         return TRUE;
  1116.  
  1117.     if (self.weapon == IT_AXE)
  1118.         return TRUE;
  1119.     
  1120.     self.weapon = W_BestWeapon ();
  1121.  
  1122.     W_SetCurrentAmmo ();
  1123.     
  1124. // drop the weapon down
  1125.     return FALSE;
  1126. };
  1127.  
  1128. /*
  1129. ============
  1130. W_Attack
  1131.  
  1132. An attack impulse can be triggered now
  1133. ============
  1134. */
  1135. void()    player_axe1;
  1136. void()    player_axeb1;
  1137. void()    player_axec1;
  1138. void()    player_axed1;
  1139. void()    player_shot1;
  1140. void()    player_nail1;
  1141. void()    player_light1;
  1142. void()    player_rocket1;
  1143.  
  1144. void() W_Attack =
  1145. {
  1146.     local    float    r;
  1147.  
  1148.     if (!W_CheckNoAmmo ())
  1149.         return;
  1150.  
  1151.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  1152.     self.show_hostile = time + 1;    // wake monsters up
  1153.  
  1154.     if (self.weapon == IT_AXE)
  1155.     {
  1156.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  1157.         r = random();
  1158.         if (r < 0.25)
  1159.             player_axe1 ();
  1160.         else if (r<0.5)
  1161.             player_axeb1 ();
  1162.         else if (r<0.75)
  1163.             player_axec1 ();
  1164.         else
  1165.             player_axed1 ();
  1166.         self.attack_finished = time + 0.5;
  1167.     }
  1168.     else if (self.weapon == IT_SHOTGUN)
  1169.     {
  1170.         player_shot1 ();
  1171.         W_FireShotgun ();
  1172.                 self.attack_finished = time + 0.5;
  1173.     }
  1174.     else if (self.weapon == IT_SUPER_SHOTGUN)
  1175.     {
  1176.         player_shot1 ();
  1177.         W_FireSuperShotgun ();
  1178.                 self.attack_finished = time + 0.7;
  1179.     }
  1180.     else if (self.weapon == IT_NAILGUN)
  1181.     {
  1182.         player_nail1 ();
  1183.     }
  1184.     else if (self.weapon == IT_SUPER_NAILGUN)
  1185.     {
  1186.         player_nail1 ();
  1187.     }
  1188.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  1189.     {
  1190.         player_rocket1();
  1191.         W_FireGrenade();
  1192.                 self.attack_finished = time + 0.6;
  1193.     }
  1194.         else if (self.weapon == IT_PIPEBOMB_LAUNCHER)
  1195.     {
  1196.         player_rocket1();
  1197.                 W_FirePipeBomb();
  1198.                 self.attack_finished = time + 0.6;
  1199.     }
  1200.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1201.     {
  1202.         player_rocket1();
  1203.         W_FireRocket();
  1204.         self.attack_finished = time + 0.8;
  1205.     }
  1206.         else if (self.weapon == IT_MINE_LAUNCHER)
  1207.         {
  1208.                 player_rocket1();
  1209.                 W_LayProximityMine();
  1210.                 self.attack_finished = time + 0.6;
  1211.         }
  1212.     else if (self.weapon == IT_LIGHTNING)
  1213.     {
  1214.         player_light1();
  1215.         self.attack_finished = time + 0.1;
  1216.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  1217.     }
  1218. };
  1219.  
  1220. /*                                  
  1221. ============
  1222. W_ChangeWeapon
  1223.  
  1224. ============
  1225. */
  1226. void() W_ChangeWeapon =
  1227. {
  1228.     local    float    it, am, fl;
  1229.     
  1230.     it = self.items;
  1231.     am = 0;
  1232.     
  1233.     if (self.impulse == 1)
  1234.     {
  1235.         fl = IT_AXE;
  1236.     }
  1237.     else if (self.impulse == 2)
  1238.     {
  1239.         fl = IT_SHOTGUN;
  1240.         if (self.ammo_shells < 1)
  1241.             am = 1;
  1242.     }
  1243.     else if (self.impulse == 3)
  1244.     {
  1245.         fl = IT_SUPER_SHOTGUN;
  1246.         if (self.ammo_shells < 2)
  1247.             am = 1;
  1248.     }        
  1249.     else if (self.impulse == 4)
  1250.     {
  1251.         fl = IT_NAILGUN;
  1252.         if (self.ammo_nails < 1)
  1253.             am = 1;
  1254.     }
  1255.     else if (self.impulse == 5)
  1256.     {
  1257.         fl = IT_SUPER_NAILGUN;
  1258.         if (self.ammo_nails < 2)
  1259.             am = 1;
  1260.     }
  1261.     else if (self.impulse == 6)
  1262.     {
  1263.         if (self.weapon == IT_GRENADE_LAUNCHER)
  1264.                 {
  1265.                          fl = IT_PIPEBOMB_LAUNCHER;
  1266.                          sprint(self, "Pipebomb launcher\n");
  1267.                 }   
  1268.         else fl = IT_GRENADE_LAUNCHER;
  1269.                 if (self.ammo_rockets < 1)
  1270.                          am = 1;
  1271.              
  1272.         }
  1273.         else if (self.impulse == 7)
  1274.     {
  1275.         if (self.weapon == IT_ROCKET_LAUNCHER)
  1276.                 {
  1277.                         fl = IT_MINE_LAUNCHER;
  1278.                         sprint(self, "Proximity Mine launcher\n");
  1279.                 }
  1280.         else fl = IT_ROCKET_LAUNCHER;
  1281.         if (self.ammo_rockets < 1)
  1282.             am = 1;
  1283.     }
  1284.     else if (self.impulse == 8)
  1285.     {
  1286.         fl = IT_LIGHTNING;
  1287.         if (self.ammo_cells < 1)
  1288.             am = 1;
  1289.     }
  1290.  
  1291.     self.impulse = 0;
  1292.     
  1293.     if (!(self.items & fl))
  1294.     {    // don't have the weapon or the ammo
  1295.                 sprint (self, "no weapon.\n");
  1296.         return;
  1297.     }
  1298.     
  1299.     if (am)
  1300.     {    // don't have the ammo
  1301.         sprint (self, "not enough ammo.\n");
  1302.         return;
  1303.     }
  1304.  
  1305. //
  1306. // set weapon, set ammo
  1307. //
  1308.     self.weapon = fl;        
  1309.     W_SetCurrentAmmo ();
  1310. };
  1311.  
  1312. /*
  1313. ============
  1314. CheatCommand
  1315. ============
  1316. */
  1317. void() GiveGren =
  1318. {
  1319.         self.items = self.items |
  1320.                 IT_GRENADE_LAUNCHER |        
  1321.                 IT_ROCKET_LAUNCHER;
  1322. };        
  1323. void() GrenUp =
  1324. {
  1325.         temp2 = temp2 + 1;
  1326.  
  1327.         if (temp2 == 1)
  1328.         sprint(self,"Grenade is plain old Grenade\n");
  1329.  
  1330.         if (temp2 == 2)
  1331.         sprint(self,"Grenade is Ogre head\n");
  1332.  
  1333.         if (temp2 == 3)
  1334.         sprint(self,"Grenade is Gib1\n");
  1335.  
  1336.         if (temp2 == 4)
  1337.         sprint(self,"Grenade is Gib2\n");
  1338.  
  1339.         if (temp2 == 5)
  1340.         sprint(self,"Grenade is Gib3\n");
  1341.  
  1342.         if (temp2 == 6)
  1343.         sprint(self,"Grenade is Player head\n");
  1344.  
  1345.         if (temp2 == 7)
  1346.         sprint(self,"Grenade is Demon head\n");
  1347.  
  1348.         if (temp2 == 8)
  1349.         sprint(self,"Grenade is Shambler head\n");
  1350.  
  1351.         if (temp2 == 9)
  1352.         sprint(self,"Grenade is Knight head\n");
  1353.  
  1354.         if (temp2 == 10)
  1355.         sprint(self,"Grenade is Grunt head\n");
  1356.  
  1357.         if (temp2 == 11)
  1358.         sprint(self,"Grenade is Invisible\n");
  1359.  
  1360.         if (temp2 == 12)
  1361.         temp2 = 11;
  1362.     self.impulse = 0;
  1363. };
  1364. void() GrenDown =
  1365. {
  1366.         temp2 = temp2 - 1;
  1367.  
  1368.         if (temp2 == 1)
  1369.         sprint(self,"Grenade is plain old Grenade\n");
  1370.  
  1371.         if (temp2 == 2)
  1372.         sprint(self,"Grenade is Ogre head\n");
  1373.  
  1374.         if (temp2 == 3)
  1375.         sprint(self,"Grenade is Gib1\n");
  1376.  
  1377.         if (temp2 == 4)
  1378.         sprint(self,"Grenade is Gib2\n");
  1379.  
  1380.         if (temp2 == 5)
  1381.         sprint(self,"Grenade is Gib3\n");
  1382.  
  1383.         if (temp2 == 6)
  1384.         sprint(self,"Grenade is Player head\n");
  1385.  
  1386.         if (temp2 == 7)
  1387.         sprint(self,"Grenade is Demon head\n");
  1388.  
  1389.         if (temp2 == 8)
  1390.         sprint(self,"Grenade is Shambler head\n");
  1391.  
  1392.         if (temp2 == 9)
  1393.         sprint(self,"Grenade is Knight head\n");
  1394.  
  1395.         if (temp2 == 10)
  1396.         sprint(self,"Grenade is Grunt head\n");
  1397.  
  1398.         if (temp2 == 11)
  1399.         sprint(self,"Grenade is Invisible\n");
  1400.  
  1401.  
  1402.         if (temp2 == 0)
  1403.         temp2 = 1;
  1404.  
  1405.     self.impulse = 0;
  1406. };
  1407. void() PentCommand =
  1408. {
  1409.     if (deathmatch || coop)
  1410.         return;
  1411.  
  1412.         self.invincible_time = 1;
  1413.         self.invincible_finished = time + 30;
  1414.         self.items = self.items | IT_INVULNERABILITY;
  1415.         dprint("You are invulnerable\n");
  1416.     self.impulse = 0;
  1417. };
  1418. void() BioCommand =
  1419. {
  1420.     if (deathmatch || coop)
  1421.         return;
  1422.  
  1423.         self.rad_time = 1;
  1424.         self.radsuit_finished = time + 30;
  1425.         self.items = self.items | IT_SUIT;
  1426.         dprint("You are biosuited\n");
  1427.     self.impulse = 0;
  1428. };
  1429. void() RingCommand =
  1430. {
  1431.     if (deathmatch || coop)
  1432.         return;
  1433.  
  1434.         self.invisible_time = 1;
  1435.         self.invisible_finished = time + 30;
  1436.         self.items = self.items | IT_INVISIBILITY;
  1437.         dprint("You are invisible\n");
  1438.     self.impulse = 0;
  1439. };
  1440. void() CheatCommand =
  1441. {
  1442.     if (deathmatch || coop)
  1443.         return;
  1444.  
  1445.     self.ammo_rockets = 100;
  1446.     self.ammo_nails = 200;
  1447.     self.ammo_shells = 100;
  1448.     self.items = self.items | 
  1449.         IT_AXE |
  1450.         IT_SHOTGUN |
  1451.         IT_SUPER_SHOTGUN |
  1452.         IT_NAILGUN |
  1453.         IT_SUPER_NAILGUN |
  1454.         IT_GRENADE_LAUNCHER |
  1455.         IT_ROCKET_LAUNCHER |
  1456.         IT_KEY1 | IT_KEY2;
  1457.  
  1458.     self.ammo_cells = 200;
  1459.     self.items = self.items | IT_LIGHTNING;
  1460.  
  1461.     self.weapon = IT_ROCKET_LAUNCHER;
  1462.     self.impulse = 0;
  1463.     W_SetCurrentAmmo ();
  1464. };
  1465.  
  1466. /*
  1467. ============
  1468. CycleWeaponCommand
  1469.  
  1470. Go to the next weapon with ammo
  1471. ============
  1472. */
  1473. void() CycleWeaponCommand =
  1474. {
  1475.     local    float    it, am;
  1476.     
  1477.     it = self.items;
  1478.     self.impulse = 0;
  1479.     
  1480.     while (1)
  1481.     {
  1482.         am = 0;
  1483.  
  1484.         if (self.weapon == IT_LIGHTNING)
  1485.         {
  1486.             self.weapon = IT_AXE;
  1487.         }
  1488.         else if (self.weapon == IT_AXE)
  1489.         {
  1490.             self.weapon = IT_SHOTGUN;
  1491.             if (self.ammo_shells < 1)
  1492.                 am = 1;
  1493.         }
  1494.         else if (self.weapon == IT_SHOTGUN)
  1495.         {
  1496.             self.weapon = IT_SUPER_SHOTGUN;
  1497.             if (self.ammo_shells < 2)
  1498.                 am = 1;
  1499.         }        
  1500.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1501.         {
  1502.             self.weapon = IT_NAILGUN;
  1503.             if (self.ammo_nails < 1)
  1504.                 am = 1;
  1505.         }
  1506.         else if (self.weapon == IT_NAILGUN)
  1507.         {
  1508.             self.weapon = IT_SUPER_NAILGUN;
  1509.             if (self.ammo_nails < 2)
  1510.                 am = 1;
  1511.         }
  1512.         else if (self.weapon == IT_SUPER_NAILGUN)
  1513.         {
  1514.             self.weapon = IT_GRENADE_LAUNCHER;
  1515.             if (self.ammo_rockets < 1)
  1516.                 am = 1;
  1517.         }
  1518.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1519.         {
  1520.                         self.weapon = IT_PIPEBOMB_LAUNCHER;
  1521.             if (self.ammo_rockets < 1)
  1522.                 am = 1;
  1523.                         sprint(self, "Pipebomb launcher\n");
  1524.                 }
  1525.                 else if (self.weapon == IT_PIPEBOMB_LAUNCHER)
  1526.                 {
  1527.                         self.weapon = IT_ROCKET_LAUNCHER;
  1528.                         if (self.ammo_rockets < 1)
  1529.                 am = 1;
  1530.                 }
  1531.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1532.                 {
  1533.                         self.weapon = IT_MINE_LAUNCHER;
  1534.                         if (self.ammo_rockets < 1)
  1535.                                 am = 1;
  1536.                         sprint(self, "Proximity Mine launcher\n");
  1537.                 }
  1538.                 else if (self.weapon == IT_MINE_LAUNCHER)
  1539.             {
  1540.             self.weapon = IT_LIGHTNING;
  1541.             if (self.ammo_cells < 1)
  1542.                 am = 1;
  1543.         }
  1544.     
  1545.         if ( (self.items & self.weapon) && am == 0)
  1546.         {
  1547.             W_SetCurrentAmmo ();
  1548.             return;
  1549.         }
  1550.     }
  1551.  
  1552. };
  1553.  
  1554. /*
  1555. ============
  1556. ServerflagsCommand
  1557.  
  1558. Just for development
  1559. ============
  1560. */
  1561. void() ServerflagsCommand =
  1562. {
  1563.     serverflags = serverflags * 2 + 1;
  1564. };
  1565.  
  1566. void() QuadCheat =
  1567. {
  1568.     if (deathmatch || coop)
  1569.         return;
  1570.     self.super_time = 1;
  1571.     self.super_damage_finished = time + 30;
  1572.     self.items = self.items | IT_QUAD;
  1573.     dprint ("quad cheat\n");
  1574. };
  1575.  
  1576. /*
  1577. ============
  1578. ImpulseCommands
  1579.  
  1580. ============
  1581. */
  1582. void() ImpulseCommands =
  1583. {
  1584.     if (self.impulse >= 1 && self.impulse <= 8)
  1585.         W_ChangeWeapon ();
  1586.  
  1587.     if (self.impulse == 9)
  1588.         CheatCommand ();
  1589.     if (self.impulse == 10)
  1590.         CycleWeaponCommand ();
  1591.     if (self.impulse == 11)
  1592.         ServerflagsCommand ();
  1593.  
  1594.     if (self.impulse == 255)
  1595.         QuadCheat ();
  1596.  
  1597.         if (self.impulse == 254)
  1598.                 PentCommand ();
  1599.  
  1600.         if (self.impulse == 253)
  1601.                 BioCommand ();
  1602.  
  1603.         if (self.impulse == 252)
  1604.                 RingCommand ();
  1605.  
  1606.         if (self.impulse == 63)
  1607.                 DetPipeBombs ();
  1608.  
  1609.         if (self.impulse == 62)
  1610.                 GrenUp ();
  1611.  
  1612.         if (self.impulse == 61)
  1613.                 GrenDown ();
  1614.  
  1615.         if (self.impulse == 64)
  1616.                 GiveGren ();
  1617.        self.impulse = 0;
  1618. };
  1619.  
  1620. /*
  1621. ============
  1622. W_WeaponFrame
  1623.  
  1624. Called every frame so impulse events can be handled as well as possible
  1625. ============
  1626. */
  1627. void() W_WeaponFrame =
  1628. {
  1629.     if (time < self.attack_finished)
  1630.         return;
  1631.  
  1632.     ImpulseCommands ();
  1633.     
  1634. // check for attack
  1635.     if (self.button0)
  1636.     {
  1637.         SuperDamageSound ();
  1638.         W_Attack ();
  1639.     }
  1640. };
  1641.  
  1642. /*
  1643. ========
  1644. SuperDamageSound
  1645.  
  1646. Plays sound if needed
  1647. ========
  1648. */
  1649. void() SuperDamageSound =
  1650. {
  1651.     if (self.super_damage_finished > time)
  1652.     {
  1653.         if (self.super_sound < time)
  1654.         {
  1655.             self.super_sound = time + 1;
  1656.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1657.         }
  1658.     }
  1659.     return;
  1660. };
  1661.  
  1662.  
  1663.